package com.huilian.iotbox.admin.wap.controller;

import com.huilian.iotbox.admin.wap.service.DeviceTypeService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.dto.DeviceDto;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @date 2021/1/9 11:33
 */
@RestController
@RequestMapping("/api/deviceType")
public class DeviceTypeController extends UserInfoController {
    @Autowired
    private DeviceTypeService deviceTypeService;

    @GetMapping("/findAllDeviceType")
    public ServerResponse findAllDeviceType(HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        return ServerResponse.createBySuccess(deviceTypeService.findAllDeviceType());
    }

    /**
     * 查询当前已有所有设备类型
     * @param request
     * @return
     */
    @GetMapping("/curr")
    public ServerResponse findCurrDeviceType(HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        return ServerResponse.createBySuccess(deviceTypeService.findCurrDeviceType(userInfo));
    }

    /**
     * 根据设备类型查询设备
     * */
    @GetMapping("/findDeviceBydeviceIdGrouping")
    public ServerResponse findDeviceBydeviceIdGrouping(HttpServletRequest request, DeviceDto deviceDto) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        return deviceTypeService.findDeviceBydeviceIdGrouping(deviceDto);
    }
}
